﻿@model RibbonModel
@using Nop.Plugin.Widgets.Ribbon.Models;
@using Nop.Core.Infrastructure;
@{
    var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
    var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;
}

@if (Model.Id > 0)
{
    <div id="entity-grid"></div>
    <script>
                $(document).ready(function () {
                    $("#entity-grid").kendoGrid({
                        dataSource: {
                            type: "json",
                            transport: {
                                read: {
                                    url: "@Html.Raw(Url.Action("RibbonProductSelect", "WidgetsRibbon", new { ribbonId = Model.Id }))",
                                    type: "POST",
                                    dataType: "json"
                                },
                                update: {
                                    url: "@Html.Raw(Url.Action("RibbonProductUpdate", "WidgetsRibbon"))",
                                    type: "POST",
                                    dataType: "json"
                                },
                                destroy: {
                                    url: "@Html.Raw(Url.Action("RibbonProductDelete", "WidgetsRibbon"))",
                                    type: "POST",
                                    dataType: "json"
                                }
                            },
                            schema: {
                                data: "Data",
                                total: "Total",
                                errors: "Errors",
                                model: {
                                    id: "Id",
                                    fields: {
                                        RibbonId: { editable: false, type: "number" },
                                        productId: { editable: true, type: "number" },
                                        Published: { editable: true, type: "boolean" }
                                    }
                                }
                            },
                            requestEnd: function (e) {
                                if (e.type == "update") {
                                    this.read();
                                }
                            },
                            error: function (e) {
                                display_kendoui_grid_error(e);
                                // Cancel the changes
                                this.cancelChanges();
                            },
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true
                        },
                        pageable: {
                            refresh: true,
                            numeric: false,
                            previousNext: false,
                            info: false
                        },
                        editable: {
                            confirmation: false,
                            mode: "inline"
                        },
                        scrollable: false,
                        columns: [{
                            field: "ProductName",
                            title: "@T("Plugins.Widgets.Ribbon.Fields.ProductName")",
                            width: 200
                            }, {
                            field: "Published",
                            title: "@T("Plugins.Widgets.Ribbon.Fields.Published")",
                            width: 100,
                            headerAttributes: { style: "text-align:center" },
                            attributes: { style: "text-align:center" },
                            template: '<img src="@Url.Content("~/Administration/Content/images/")active-#=Published#.gif" />'
                        }, {
                            command: { name: "edit", text: "@T("Admin.Common.Edit")" },
                            title: "@T("Admin.Common.Edit")",
                            width: 150
                        },
                        {
                            command: [{
                                name: "destroy",
                                text: "@T("Admin.Common.Delete")"}],
                                width: 200
                        }]
                    });
                });
            </script>
    

    <p>
        <strong>
             <input type="submit" id="btnAddNewProduct" name="btnAddNewProduct" value="@T("Admin.Catalog.Categories.Products.AddNew")" onclick="javascript:OpenWindow('@(Url.Action("ProductAddPopup", "WidgetsCarousel", new { carouselId = Model.Id, btnId = "btnRefreshProducts", formId = "carousel-form" }))', 800, 800, true); return false;" class="k-button" />
            <input type="submit" id="btnRefreshProducts" name="btnRefreshProducts" style="display: none" />
            <script type="text/javascript">
                $(document).ready(function () {
                    $('#btnRefreshProducts').click(function () {
                        //refresh grid
                        var optionsGrid = $("#entity-grid").data('kendoGrid');
                        optionsGrid.dataSource.read();

                        //return false to don't reload a page
                        return false;
                    });
                });
            </script>

        </strong>
    </p>
}
else
{
    @T("Plugins.Widgets.Ribbon.SaveBeforeEdit")
}


